package workai.fcx.com.message_module.ui.main;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.hxh.component.basicore.Base.app.AppManager;
import com.hxh.component.basicore.Base.onRecyItemLongClick;
import com.hxh.component.basicore.component.mvp.view.BaseLazyFragment;
import com.hxh.component.basicore.ui.recycleview.mrecycleview.MDataSource;
import com.hxh.component.basicore.ui.recycleview.mrecycleview.MRecycleView;
import com.hxh.component.basicore.ui.recycleview.mrecycleview.NetRepository;
import com.hxh.component.basicore.ui.recycleview.mrecycleview.NetResultBean;
import com.hxh.component.basicore.ui.recycleview.mrecycleview.PaginationBuilder;

import com.hxh.component.business.ui.MyRecyItemDecoration;

import java.util.HashMap;

import rx.Observable;
import workai.fcx.com.message_module.R;
import workai.fcx.com.message_module.adapter.MyMsgAdapter;
import workai.fcx.com.message_module.api.ApiFactory;
import workai.fcx.com.message_module.bean.MyMsgDTO;

/**
 * 招聘管理主页
 *
 * @author fucx
 */

public class MessageHomeFragment extends BaseLazyFragment<MessageHomePresenter> implements MessageHomeContract.V, View.OnClickListener {


    public static MessageHomeFragment newInstance() {
        return new MessageHomeFragment();
    }

    private MRecycleView recycleview;
    private MDataSource mDataSource;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_message_home;
    }

    @Override
    public void initData(Bundle saveInstanceState) {
        initView();
        setListener();
    }

    private void initView() {
        recycleview = findViewBy(R.id.recycleview);
    }

    private void setListener() {
    }

    private void initRecycleview() {
        mDataSource = recycleview.setAdapter(new MyMsgAdapter(getmContext(), new onRecyItemLongClick<MyMsgDTO, MyMsgAdapter.VH>() {
            @Override
            public void onLongClick(int position, int tag, MyMsgDTO data, MyMsgAdapter.VH holder) {
//                showDeleteMsg(false,data.getId());
            }
        }))

                .setLoadingEnable(true, true)
                .setDividerItemDecoration(new MyRecyItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, 2, R.color.bg_f4f4f4))
                .getDataRepositoryBuilder()
                .setNetRepository(new NetRepository() {
                    @Override
                    public Observable<NetResultBean> getData(HashMap params) {
                        return ApiFactory.getMsgs(params);
                    }
                })
                .setPagination(new PaginationBuilder
                        .Builder()
                        .setPageSize(15)
                        .setPageIndex(0)
                        .setPageSizeFieldName("limit")
                        .setPageIndexFieldName("offset")
                        .create())
                .setNoDataStateWhenRequest(MDataSource.HAVEDATA_FORCEDCOVER);
        mDataSource.fetch();
    }


    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
//        initRecycleview();
    }


    @Override
    public MessageHomePresenter newP() {
        return new MessageHomePresenter();
    }


    @Override
    public void onClick(View v) {
        if (AppManager.isDoubleClick(1000)) return;

        int id = v.getId();

    }
}
